#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<sys/mman.h>
#include<sys/stat.h>
#include<errno.h>
#include<fcntl.h>
#include<unistd.h> 
#include<pthread.h>

int
main(int argc, char* args[])
{
	int fd;
	fd = open("mmaptest", O_RDWR | O_CREAT, 0644);
	if(fd < 0){
		perror("open error");
		exit(1);
	}
	
	if(ftruncate(fd, 100) < 0){
		perror("ftruncate error");
		exit(1);
	}
	
//	int len;
	int len = lseek(fd, 0, SEEK_END);
	if(len < 0){
		perror("lseek error");
		exit(1);
	}
//	printf("there\n");
	printf("len = %d\n",len);

	char* p = nullptr;
	p = (char*) mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
	if(p == MAP_FAILED){
//		printf("error in mmap\n");
		perror("mmap error");
		exit(1);
	}

	sprintf(p,"hellow, map\n");
	

	exit(0);
}
